const app = new Vue({
    el: "#app",
    data: {
        username: "",
        password: "",
        message: ""
    },
    withCredentials: true,
    methods: {

        //登录
        login: function() {
            //检验用户名密码是否为空
            if(this.username === '' || this.password === ''){
                layer.msg("用户名或者密码不能为空");
            } else {
                //layui加载框
                const load = layer.load({time: 2000});
                axios.post("/user/login", {
                    account: this.username,
                    password: this.password
                }, ).then(function(response) {
                    //请求响应回来就进行关闭
                    layer.close(load);
                    const resultInfo = response.data;
                    this.message = resultInfo.message;
                    //判断是否跳转页面
                    if (resultInfo.status === 1) {
                        //弹窗显示登录信息
                        layer.msg(this.message, {time: 1500,});
                        location.href = "/index.html";
                    } else {
                        //弹窗显示登录信息
                        layer.msg(this.message, {time: 1500});
                    }
                }).catch();
            }
        },

        //注册页面路由
        toRegister: function() {
            location.href = "/register.html";
        }
    }
})

$('#app input').on('focus', function() {
    $(this).addClass('focus');
});
$('#app input').on('blur', function() {
    $(this).removeClass('focus');
})